import { Exclude } from 'class-transformer';
import {
  Column,
  Entity,
  JoinColumn,
  JoinTable,
  ManyToMany,
  ManyToOne,
  OneToMany,
  PrimaryGeneratedColumn,
} from 'typeorm';
import { Course } from '../../course/entities/course.entity';
import { LessonsSort } from '../../lessons-sort/entities/lessons-sort.entity';
import { Role } from '../../roles/entities/role.entity';

@Entity()
export class Teacher {
  @PrimaryGeneratedColumn()
  tid: number;

  @Column({ comment: '职工编号', unique: true })
  t_code: string;

  @Column({ comment: '姓名' })
  t_name: string;

  @Column({ comment: '性别' })
  gender: number;

  @Column({ comment: '密码' })
  @Exclude()
  password: string;

  @Column({ comment: '手机号', nullable: true })
  t_tel: number;

  @OneToMany(() => Course, (course) => course.teacher, {
    onDelete: 'SET NULL',
  })
  course: Course[];

  @OneToMany(() => LessonsSort, (lessonsSort) => lessonsSort.teacher, {
    onDelete: 'SET NULL',
  })
  lessonsSorts: LessonsSort[];

  @ManyToMany(() => Role, (role) => role.teachers)
  @JoinTable({
    name: 'teacher_role',
  })
  roles: Role[];
}
